#ifndef AI_SERVICE_NAPI_UTILS_H
#define AI_SERVICE_NAPI_UTILS_H

#include <cstring>
#include <iostream>
#include <map>
#include <optional>

#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "refbase.h"
#include "ai_service_errors.h"
#include "ai_service_data_type.h"

namespace OHOS {
namespace AIS {

struct PicDescNapi {
    int width = 0;
    int height = 0;
    int dataSize = 0;
};

struct BoxRectNapi
{
    int left = 0;
    int right = 0;
    int top = 0;
    int bottom = 0;
};

struct ObjectDescNapi {
    BoxRectNapi box = {};
    float prop = 0.0;
    int class_index = 0;   
};

struct InferResultNapi {
    int index = 0;
};

enum AsyncErrorCode
{
    FAIL = -1,
    UNKNOW = 0,
    SUCCESS = 1
};

struct AIServiceAsyncContext {
    napi_async_work asyncWork;
    napi_deferred deferred = nullptr;
    napi_ref callbackRef = nullptr;

    AsyncErrorCode status = UNKNOW;
    std::string data = "";
    int32_t modelId = -1;
    InferResult inferResult {};
    PicDesc picDesc {};
};

bool GetNapiInt32(const napi_env &env, const int32_t value, napi_value &result);
bool GetPropertyString(const napi_env &env, const napi_value &value, const std::string &type, std::string &result);
bool GetPropertyInt32(const napi_env &env, const napi_value &value, const std::string &type, int32_t &result);
void Uint8ArrayToJsValue(const napi_env &env, const uint8_t *srcData, size_t bufferSize, napi_value &result);
void SetValueUtf8String(const napi_env &env, const std::string &fieldStr, const std::string &str, napi_value &result);

} // namespace AIS
} // namespace OHOS
#endif // AI_SERVICE_NAPI_UTILS_H